home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1159.ASC < prev    next >
Text File  |  1992-11-11  |  11KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  November 11, 1992                        PAGE  :  1/7
  12.  
  13.     TITLE  :  Graying Buttons with Turbo Vision.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.        The following source code provides an example of graying a
  20.   button when using Borland's C++ Turbo Vision Framework for DOS.
  21.   A MAKEFILE is also included.
  22.  
  23.  
  24.   /****************************************************************
  25.   *                                                               *
  26.    * BUTTON.CPP                                                   *
  27.    *   This module contains code to set up a dialog box with three*
  28.    *   buttons. The first button toggles the second button between*
  29.    *   an enabled and disabled state.  The third is just an OK    *
  30.    *   button to  close the box.                                  *
  31.    *                                                              *
  32.    * SUPPORT MODULE for grey button example.                      *
  33.    *                                                              *
  34.    ****************************************************************
  35.    *                                                              *
  36.    * This code was written by Borland Technical Support.          *
  37.    * It is provided as is with no warranties expressed or implied *
  38.    *                                                              *
  39.    ***************************************************************/
  40.  
  41.   #define Uses_TRect
  42.   #define Uses_TView
  43.   #define Uses_TEvent
  44.   #define Uses_TButton
  45.   #define Uses_TLabel
  46.   #define Uses_TDialog
  47.   #define Uses_MsgBox
  48.   #include <tv.h>
  49.  
  50.   #pragma hdrstop
  51.  
  52.   #include "button.h"
  53.   #include "cmds.h"
  54.  
  55.  
  56.   /****************************************************************
  57.    *                                                              *
  58.    * class TButtonDialog                                          *
  59.    *                                                              *
  60.    ****************************************************************
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  November 11, 1992                        PAGE  :  2/7
  78.  
  79.     TITLE  :  Graying Buttons with Turbo Vision.
  80.  
  81.  
  82.  
  83.  
  84.    * TButtonDialog::TButtonDialog                                 *
  85.    *   Initialize the dialog box - add the appropriate labels and *
  86.    *   buttons and set option to center it on the screen.         *
  87.    ****************************************************************/
  88.  
  89.   TButtonDialog::TButtonDialog(TRect& r, char *title) :
  90.       TDialog( r, title ),
  91.       TWindowInit( initFrame )
  92.   {
  93.       TButton *TB;
  94.  
  95.       TB = new TButton( TRect(2,2,12,4), "~T~oggle", cmToggle,
  96.                         bfNormal );
  97.       insert( TB );
  98.       insert( new TLabel( TRect(13,2,37,3), "Toggle
  99.                       enabled/disabled", TB ) );
  100.  
  101.       TB = new TButton( TRect(2,4,12,6), "T~e~ster", cmTester,
  102.                       bfNormal );
  103.       insert( TB );
  104.       insert( new TLabel( TRect(13,4,25,5), "Test Button", TB ) );
  105.  
  106.       insert( new TButton( TRect(14,7,24,9), "O~K~", cmOK,
  107.                       bfDefault ) );
  108.  
  109.       options |= ofCentered;
  110.       selectNext( False );
  111.   }
  112.  
  113.  
  114.   /****************************************************************
  115.    * TTestList::handleEvent
  116.    *   Handle the command events from the <Toggle> and <Tester>
  117.        buttons.
  118.    ****************************************************************/
  119.  
  120.   void TButtonDialog::handleEvent( TEvent& event )
  121.   {
  122.       TDialog::handleEvent( event );
  123.  
  124.       if( event.what == evCommand )
  125.       {
  126.           switch( event.message.command )
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  November 11, 1992                        PAGE  :  3/7
  144.  
  145.     TITLE  :  Graying Buttons with Turbo Vision.
  146.  
  147.  
  148.  
  149.  
  150.           {
  151.           case cmToggle:             // Toggle tester button on/off
  152.               if( commandEnabled( cmTester ) )
  153.                   disableCommand( cmTester );
  154.               else
  155.                   enableCommand( cmTester );
  156.               break;
  157.  
  158.           case cmTester:             // Put up a message box...
  159.               messageBox( "Tester button pressed...",
  160.                           mfOKButton | mfInformation
  161.                         );
  162.               break;
  163.  
  164.           default:
  165.               return;
  166.           }
  167.           clearEvent(event);
  168.       }
  169.   }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.   /****************************************************************
  182.    * BUTTON.H                                                     *
  183.    *   Header file to support BUTTON.CPP.  Contains the dialog    *
  184.    *   class                                                      *
  185.    *   used for the buttons.                                      *
  186.    *                                                              *
  187.    * HEADER FILE for grey button example.                         *
  188.    *                                                              *
  189.    ****************************************************************
  190.    *                                                              *
  191.    * This code was written by Borland Technical Support.          *
  192.    * It is provided as is with no warranties expressed or implied.*
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  207.   VERSION  :  3.1
  208.        OS  :  DOS
  209.      DATE  :  November 11, 1992                        PAGE  :  4/7
  210.  
  211.     TITLE  :  Graying Buttons with Turbo Vision.
  212.  
  213.  
  214.  
  215.  
  216.    *                                                              *
  217.    ****************************************************************/
  218.  
  219.   class TButtonDialog : public TDialog
  220.   {
  221.   public:
  222.       TButtonDialog( TRect& r, char *title );
  223.       virtual void handleEvent( TEvent& event );
  224.   };
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.   /****************************************************************
  236.    * CMDS.H                                                       *
  237.    *   This module contains various commands used in the main     *
  238.    *   message  system (including the menu bar, status line, and  *
  239.    *   miscellaneous dialog boxes.)                               *
  240.    *                                                              *
  241.    * HEADER FILE for grey button example.                         *
  242.    *                                                              *
  243.    ****************************************************************
  244.    *                                                              *
  245.    * This code was written by Borland Technical Support.          *
  246.    * It is provided as is with no warranties expressed or implied.*
  247.    *                                                              *
  248.    ****************************************************************/
  249.  
  250.   #ifndef _CMDS_H
  251.   #define _CMDS_H
  252.  
  253.   const unsigned short cmButtonDialog = 100;
  254.   const unsigned short cmToggle       = 101;
  255.   const unsigned short cmTester       = 102;
  256.  
  257.   #endif
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  273.   VERSION  :  3.1
  274.        OS  :  DOS
  275.      DATE  :  November 11, 1992                        PAGE  :  5/7
  276.  
  277.     TITLE  :  Graying Buttons with Turbo Vision.
  278.  
  279.  
  280.  
  281.  
  282.   /****************************************************************
  283.    * TEST.CPP                                                     *
  284.    *   This module contains the Turbo Vision application code to  *
  285.    *   run this example.  It sets up the necessary menus to bring *
  286.    *   up the test module represented by this demo.               *
  287.    * TEST MODULE for grey button example.                         *
  288.    *                                                              *
  289.    ****************************************************************
  290.    *                                                              *
  291.    * This code was written by